<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('我的待办')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreateTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreateTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('business:carPackageAudit:edit')}]];
        var removeFlag = [[${@permission.hasPermi('business:carPackageAudit:remove')}]];
        var prefix = ctx + "business/todo";
        var auditStatus = [[${@dict.getType('cpa_status')}]];

        $(function() {
            var options = {
                url: prefix + "/list",
                modalName: "我的待办",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '审核编号',
                },
                {
                    field: 'serviceItem.name',
                     title: '套餐名称',
                },
                {
                    field:'serviceItem.discountPrice',
                    title: '套餐价格',
                },
                {
                    field:'serviceItem.info',
                    title: '套餐备注',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field:'createByName',
                    title: '创建人'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                     field: 'taskName',
                     title: '当前任务名称'
                },
                {
                    field: 'status',
                    title: '审核状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(auditStatus, value);
                    }
                },
                {
                    field: 'auditors',
                    title: '当前审核人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status==0){
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="showAuditDialog(\'' + row.taskId + '\', \'' + row.taskName + '\')"><i class="fa fa-edit"></i> 审批</a> ');
                        }else if(row.status==1) {
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="openServiceItemsEditPage(\'' + row.id + '\')"><i class="fa fa-edit"></i> 修改表单</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="reApply(\'' + row.taskId + '\', \'' + row.id + '\')"><i class="fa fa-edit"></i> 重新申请</a> ');
                        }
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.instanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.instanceId + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function showHistoryDialog(instanceId) {
            $.modal.open("查看历史记录",'/business/carPackageAudit/historyList/'+instanceId);

        }
        function reApply(taskId,carPackageAuditId){
            $.modal.confirm("确认需要重新发起申请吗", function() {
                $.operate.post(prefix + "/reApply", { "taskId": taskId, "carPackageAuditId": carPackageAuditId });
            })
        }

        function openServiceItemsEditPage(carPackageAuditId) {
            var url = prefix + "/serviceItem/edit?carPackageAuditId=" + carPackageAuditId;
            $.modal.open("修改服务项", url);

        }
        function showAuditDialog(taskId,taskName) {
            var url = prefix + "/showAuditDialog/" + taskId;
            $.modal.open(taskName, url);
        }
        
        function showProcessImgDialog(instanceId) {
            $.modal.open("流程进度图",'/business/carPackageAudit/processImg/'+instanceId);

        }
        function cancelApply(instanceId,id) {
            $.modal.confirm("确认要撤销审核吗？",function () {
                //发起撤销的请求到后台 将instance传递到后台
                var url = prefix+"/cancelApply/"+id;
                var data = {"instanceId":instanceId};
                $.operate.submit(url,"post","json",data);
            });
        }
    </script>
</body>
</html>